package com.itheima.day08.myTreeSet.test2$.service;

import com.itheima.day08.myTreeSet.test2$.dao.StudentDao;
import com.itheima.day08.myTreeSet.test2$.domain.Student;

import java.util.Scanner;
import java.util.TreeSet;

public class StudentService {
    static Scanner sc = new Scanner(System.in);
    StudentDao studentDao = new StudentDao();
    // 添加学生信息
    public boolean addStudent(){
        String id;
        String name;

        while(true){

            while(true){
                System.out.println("请输入学号：");
                id = sc.nextLine();
                id.trim();
                String substring = null;
                try {
                    substring = id.substring(0, 7);
                } catch (StringIndexOutOfBoundsException e) {
                    System.out.println("格式不规范请重新输入：\n");
                    continue;
                }
                if("itheima".equals(substring)){
                    break;
                }else {
                    System.out.println("输入失败，请重新输入：\n");
                }

            }

            System.out.println("请输入姓名：");
            name = sc.nextLine();
            break;
        }

        boolean boo = studentDao.addStudent(id, name);
        if(boo == true){
            return true;
        }else{
            return false;
        }
    }
    // 取数据
    public TreeSet<Student> getStudent(){
        return studentDao.getStudent();
    }
}
